using System;
using System.Collections.Generic;
using Moq;
using SpecMaker.Core.Dsl;
using SpecMaker.Core.Interfaces;
using System.Linq;
using SpecMakerForums.Domain;
using SpecMakerForums.Domain.Interfaces;
using It=SpecMaker.Core.Dsl.It;

namespace SpecMakerForums.Specs
{
    public class SpecViewPosts : ISpecContainer
    {
        public Spec[] RunSpecs()
        {
            var specs = new List<Spec>();

            var viewspec = Spec.Describes<Post>().WithContext("When a user tries to view it").WithFollowingRules(
                It.Should("check to see if user is allowed to see the post", ()=>
                                                                                 { 
                                                                                     
                                                                                     var validationservice = new Mock<IUserValidationService>();
                                                                                     var post = new Post(validationservice.Object);

                                                                                     bool canuse =
                                                                                         post.CanUserView("annie");
                                                                                    
                                                                                     
                                                                                     validationservice.Verify(auth=>auth.CheckUserPermForPost(post, "annie"));
                                                                                      

                                                                                 }));
              
            var allowedspec =
                Spec.Describes<Post>().WithContext("When an allowed user is viewing the post").WithFollowingRules(
                  It.Should("display post for allowed users", RuleIs.Pending));

            var deniedspec =
                Spec.Describes<Post>().WithContext("When a denied user is viewing the post").WithFollowingRules(
                It.Should("not display the post", RuleIs.Pending),
                It.Should("redirect user to 'not allowed' page", RuleIs.Pending)
                    );
            specs.AddRange(new[] {viewspec, allowedspec, deniedspec});
            return specs.ToArray();
        }
    }
}